package com.linpq.road.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdSpatialInfo;
import com.linpq.road.service.RdSpatialInfoService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;

/**
 * 空间信息Controller
 *
 * @author linpq
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/road/spatial_info")
public class RdSpatialInfoController extends BaseController {
    private String prefix = "road/spatial_info";

    @Autowired
    private RdSpatialInfoService rdSpatialInfoService;

    @RequiresPermissions("road:spatial_info:view")
    @GetMapping()
    public String spatial_info() {
        return prefix + "/spatial_info";
    }

    /**
     * 查询空间信息列表
     */
    @RequiresPermissions("road:spatial_info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdSpatialInfo rdSpatialInfo) {
        startPage();
        List<RdSpatialInfo> list = rdSpatialInfoService.selectRdSpatialInfoList(rdSpatialInfo);
        return getDataTable(list);
    }

    /**
     * 导出空间信息列表
     */
    @RequiresPermissions("road:spatial_info:export")
    @Log(title = "空间信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdSpatialInfo rdSpatialInfo) {
        List<RdSpatialInfo> list = rdSpatialInfoService.selectRdSpatialInfoList(rdSpatialInfo);
        ExcelUtil<RdSpatialInfo> util = new ExcelUtil<RdSpatialInfo>(RdSpatialInfo. class);
        return util.exportExcel(list, "spatial_info");
    }

    /**
     * 新增空间信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存空间信息
     */
    @RequiresPermissions("road:spatial_info:add")
    @Log(title = "空间信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdSpatialInfo rdSpatialInfo) {
        return toAjax(rdSpatialInfoService.insertRdSpatialInfo(rdSpatialInfo));
    }

    /**
     * 修改空间信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdSpatialInfo rdSpatialInfo =rdSpatialInfoService.selectRdSpatialInfoById(id);
        mmap.put("rdSpatialInfo", rdSpatialInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存空间信息
     */
    @RequiresPermissions("road:spatial_info:edit")
    @Log(title = "空间信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdSpatialInfo rdSpatialInfo) {
        return toAjax(rdSpatialInfoService.updateRdSpatialInfo(rdSpatialInfo));
    }

    /**
     * 删除空间信息
     */
    @RequiresPermissions("road:spatial_info:remove")
    @Log(title = "空间信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdSpatialInfoService.deleteRdSpatialInfoByIds(ids));
    }
}
